package com.example.zhugenew.MVP.model;

import com.example.mymvplibrary.model.BaseModel;
import com.example.zhugenew.ApiService;
import com.example.zhugenew.MVP.presenter.ICallBack;
import com.example.zhugenew.bean.newhouses.NewHouseBlockBean;
import com.example.zhugenew.bean.newhouses.NewHouseEvidenceBean;
import com.example.zhugenew.bean.newhouses.NewHouseHotListBean;
import com.example.zhugenew.bean.newhouses.NewHouseImageBean;
import com.example.zhugenew.bean.newhouses.NewListBean;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.ResourceSubscriber;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class IModel implements BaseModel {
    public void getBlockData(ICallBack<NewHouseBlockBean> newHouseBlockBeanICallBack) {
        HashMap<String, Object> allHighMap = new HashMap<>();
        allHighMap.put("app_name", "zgzf");
        allHighMap.put("on_off", "1");
        allHighMap.put("city", "bj");
        new Retrofit.Builder()
                .baseUrl(ApiService.headUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ApiService.class)
                .getBlockData(allHighMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResourceSubscriber<NewHouseBlockBean>() {
                    @Override
                    public void onNext(NewHouseBlockBean newHouseBlockBean) {
                        newHouseBlockBeanICallBack.OnSuccess(newHouseBlockBean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        newHouseBlockBeanICallBack.OnFailed(t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getImageData(ICallBack<NewHouseImageBean> iCallBack) {
        HashMap<String, Object> ImageMap = new HashMap<>();
        ImageMap.put("app_name", "zgzf");
        ImageMap.put("city", "bj");
        new Retrofit.Builder()
                .baseUrl(ApiService.headUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                .create(ApiService.class)
                .getImageData(ImageMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResourceSubscriber<NewHouseImageBean>() {
                    @Override
                    public void onNext(NewHouseImageBean newHouseImageBean) {
                        iCallBack.OnSuccess(newHouseImageBean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        iCallBack.OnFailed(t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getEvidenceData(ICallBack<NewHouseEvidenceBean> iCallBack) {

        HashMap<String, Object> evidenceMap = new HashMap<>();
        evidenceMap.put("city", "bj");
        evidenceMap.put("platform_type", "4");
        evidenceMap.put("platformType", "4");
        evidenceMap.put("type", "2");
        new Retrofit.Builder()
                .baseUrl(ApiService.headUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build().create(ApiService.class)
                .getEvidenceData(evidenceMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResourceSubscriber<NewHouseEvidenceBean>() {
                    @Override
                    public void onNext(NewHouseEvidenceBean newHouseEvidenceBean) {
                        iCallBack.OnSuccess(newHouseEvidenceBean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        iCallBack.OnFailed(t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getHotListData(ICallBack<NewHouseHotListBean> iCallBack) {
        HashMap<String, Object> hotlistMap = new HashMap<>();
        hotlistMap.put("city", "bj");
        hotlistMap.put("platform_type", "4");
        hotlistMap.put("platformType", "4");
        new Retrofit.Builder()
                .baseUrl(ApiService.headUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build()
                .create(ApiService.class)
                .getHotlistData(hotlistMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResourceSubscriber<NewHouseHotListBean>() {
                    @Override
                    public void onNext(NewHouseHotListBean newHouseHotListBean) {
                        iCallBack.OnSuccess(newHouseHotListBean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        iCallBack.OnFailed(t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void getHousesList(ICallBack<NewListBean.DataBeanX> iCallBack) {
        HashMap<String, Object> houseslistMap = new HashMap<>();
        houseslistMap.put("page", "1");
        houseslistMap.put("limit", "10");
        houseslistMap.put("city", "bj");
        houseslistMap.put("token", "mvHP0qn046aGLsGE_0KMCb2T1gHJ8kYVaQFt7HPP7rOrHDHeMV05qbQj7_fqKSRm1kZpsm3v6l6gUyy8URg9EzNdz1rF7TvX9dk_yDB9Zd_AGm0QouxUFkT-ImM4GsD");
        houseslistMap.put("app_name", "zgzf");
        houseslistMap.put("platform_type", "4");
        houseslistMap.put("platformType", "4");
        new Retrofit.Builder()
                .baseUrl(ApiService.headUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ApiService.class)
                .getHouselistData(houseslistMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new ResourceSubscriber<NewListBean>() {
                    @Override
                    public void onNext(NewListBean newListBean) {
                        iCallBack.OnSuccess(newListBean.getData());
                    }

                    @Override
                    public void onError(Throwable t) {
                        iCallBack.OnFailed(t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
 